package vip.xiaonuo.modular.business.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.exception.ServiceException;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.business.param.PointAnalysisParam;
import vip.xiaonuo.modular.business.service.PointAnalysisService;
import vip.xiaonuo.modular.manage.biindextype.service.BiIndexTypeService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: liu
 * @Date:2022/10/20
 */
@RestController
public class PointAnalysisController {

    @Resource
    private PointAnalysisService pointAnalysisService;
    
    @Resource
    private BiIndexTypeService biIndexTypeService;

    @PostMapping("/business/pointAnalysis/findPoint")
    public ResponseData findPoint(@RequestBody PointAnalysisParam param) {
        return new SuccessResponseData(pointAnalysisService.findPoint(param));
    }

    @PostMapping("/business/pointAnalysis/comparePoint")
    public ResponseData comparePoint(@RequestBody PointAnalysisParam param) {
        return new SuccessResponseData(pointAnalysisService.comparePoint(param));
    }

    @PostMapping("/business/pointAnalysis/queryThemeOrderPage")
    public ResponseData queryThemeOrderList(@RequestBody PointAnalysisParam param, HttpServletRequest request) {
        request.setAttribute("pageNo", param.getPageNo());
        request.setAttribute("pageSize", param.getPageSize());
        return new SuccessResponseData(pointAnalysisService.queryThemeOrderPage(param));
    }

    @PostMapping("/business/pointAnalysis/findArea")
    public ResponseData findArea(@RequestBody PointAnalysisParam param) {
        return new SuccessResponseData(pointAnalysisService.findArea(param));
    }

    @PostMapping("/business/pointAnalysis/indexTypeWeightTree")
    public ResponseData indexTypeWeightTree(@RequestBody PointAnalysisParam param) {
        return new SuccessResponseData(pointAnalysisService.indexTypeWeightTree());
    }

    @PostMapping("/business/pointAnalysis/getIndustryWeight")
    public ResponseData getIndustryWeight(@RequestBody PointAnalysisParam param) {
        return new SuccessResponseData(pointAnalysisService.getIndustryWeightTree(param));
    }
    @PostMapping("/business/pointAnalysis/updateIndustryWeight")
    public ResponseData updateIndustryWeight(HttpServletRequest request,@RequestBody JSONObject param) {
        Object themeId = param.get("themeId");
        if (themeId == null) {
            throw new ServiceException(9,"themeId不能为空");
        }
        request.getSession().setAttribute("INDUSTRY_"+themeId,param);
        return new SuccessResponseData();
    }

    @PostMapping("/business/pointAnalysis/queryDetailReport")
    public ResponseData queryDetailReport(@RequestBody PointAnalysisParam param) {
        return new SuccessResponseData(pointAnalysisService.queryDetailReport(param));
    }

}
